<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>对象字面量扩展语法</title>
</head>

<body>
  <script>
    // 计算的属性名
    const name = "p1"
    const name1 = "p1"
    let p = {
      [name]: {},
      [name1]: {}
    }
    p[name].x = 2
    p[name1].x = 2
    console.log(p);

    // 符号作为属性名
    const extension = Symbol('我的扩展')
    const extension1 = Symbol('我的扩展')
    let o = {
      [extension]: {},
      [extension1]: {},
    }
    o[extension].x = 0
    o[extension1].x = 5

    // 简写方法
    const NAME = "m"
    const symbol = Symbol()
    let methods = {

      "abc"(x) { return x },
      [NAME](x) { return x },
      // get [NAME]() { return this.y },
      // set [NAME](x) { return this.y = x },
      [symbol](x) { return x },
    }
    // methods[NAME] = 2
    console.log(methods[NAME](2));
    // console.log(methods[NAME]);
    console.log(methods[symbol](2));
    console.log(methods.abc(2));
  </script>
</body>

</html>